home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / e33el2.zip / emacs / 19.33 / lisp / shadowfile.el < prev    next >
Lisp/Scheme  |  1996-02-17  |  32KB  |  844 lines

  1. ;;; shadowfile.el --- automatic file copying for Emacs 19
  2.  
  3. ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu>
  6. ;; Keywords: comm
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  22. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. ;; Boston, MA 02111-1307, USA.
  24.  
  25. ;; LCD Archive Entry:
  26. ;; shadowfile|Boris Goldowsky|boris@gnu.ai.mit.edu|
  27. ;; Helps you keep identical copies of files in multiple places.|
  28. ;; $Date: 1996/01/25 01:16:55 $ |$Revision: 1.8 $|~/misc/shadowfile.el.Z|
  29.  
  30. ;; Commentary:
  31.  
  32. ;;  This package helps you to keep identical copies of files in more than one
  33. ;;  place - possibly on different machines.  When you save a file, it checks
  34. ;;  whether it is on the list of files with "shadows", and if so, it tries to
  35. ;;  copy it when you exit emacs (or use the shadow-copy-files command).
  36.  
  37. ;; Installation & Use:
  38.  
  39. ;;  Put (require 'shadowfile) in your .emacs; add clusters (if necessary)
  40. ;;  and file groups with shadow-define-cluster,
  41. ;;  shadow-define-literal-group, and shadow-define-regexp-group (see the
  42. ;;  documentation for these functions for information on how and when to
  43. ;;  use them).  After doing this once, everything should be automatic.
  44.  
  45. ;;  The lists of clusters and shadows are saved in a file called .shadows,
  46. ;;  so that they can be remembered from one emacs session to another, even
  47. ;;  (as much as possible) if the emacs session terminates abnormally.  The
  48. ;;  files needing to be copied are stored in .shadow_todo; if a file cannot
  49. ;;  be copied for any reason, it will stay on the list to be tried again
  50. ;;  next time.  The .shadows file should itself have shadows on all your
  51. ;;  accounts so that the information in it is consistent everywhere, but
  52. ;;  .shadow_todo is local information and should have no shadows.
  53.  
  54. ;;  If you do not want to copy a particular file, you can answer "no" and
  55. ;;  be asked again next time you hit C-x 4 s or exit emacs.  If you do not
  56. ;;  want to be asked again, use shadow-cancel, and you will not be asked
  57. ;;  until you change the file and save it again.  If you do not want to
  58. ;;  shadow that file ever again, you can edit it out of the .shadows
  59. ;;  buffer.  Anytime you edit the .shadows buffer, you must type M-x
  60. ;;  shadow-read-files to load in the new information, or your changes will
  61. ;;  be overwritten!
  62.  
  63. ;; Bugs & Warnings:
  64. ;;
  65. ;;  - It is bad to have two emacses both running shadowfile at the same
  66. ;;  time.  It tries to detect this condition, but is not always successful.
  67. ;;
  68. ;;  - You have to be careful not to edit a file in two locations
  69. ;;  before shadowfile has had a chance to copy it; otherwise
  70. ;;  "updating shadows" will overwrite one of the changed versions.
  71. ;;
  72. ;;  - It ought to check modification times of both files to make sure
  73. ;;  it is doing the right thing.  This will have to wait until
  74. ;;  file-newer-than-file-p works between machines.
  75. ;;
  76. ;;  - It will not make directories for you, it just fails to copy files
  77. ;;  that belong in non-existent directories.
  78. ;;
  79. ;;  Please report any bugs to me (boris@gnu.ai.mit.edu).  Also let me know
  80. ;;  if you have suggestions or would like to be informed of updates.
  81.  
  82. ;;; Code:
  83.  
  84. (provide 'shadowfile)
  85. (require 'ange-ftp)
  86.  
  87. (setq find-file-visit-truename t)    ; makes life easier with symbolic links
  88.  
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ;;; Variables
  91. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  92.  
  93. (defvar shadow-noquery nil
  94.   "*If t, always copy shadow files without asking.
  95. If nil \(the default), always ask.  If not nil and not t, ask only if there
  96. is no buffer currently visiting the file.")
  97.  
  98. (defvar shadow-inhibit-message nil
  99.   "*If nonnil, do not display a message when a file needs copying.")
  100.  
  101. (defvar shadow-inhibit-overload nil
  102.   "If nonnil, shadowfile won't redefine C-x C-c.
  103. Normally it overloads the function `save-buffers-kill-emacs' to check
  104. for files have been changed and need to be copied to other systems.")
  105.  
  106. (defvar shadow-info-file nil
  107.   "File to keep shadow information in.  
  108. The shadow-info-file should be shadowed to all your accounts to
  109. ensure consistency.  Default: ~/.shadows")
  110.  
  111. (defvar shadow-todo-file nil
  112.   "File to store the list of uncopied shadows in.
  113. This means that if a remote system is down, or for any reason you cannot or
  114. decide not to copy your shadow files at the end of one emacs session, it will
  115. remember and ask you again in your next emacs session.
  116. This file must NOT be shadowed to any other system, it is host-specific.
  117. Default: ~/.shadow_todo")
  118.  
  119. ;;; The following two variables should in most cases initialize themselves
  120. ;;; correctly.  They are provided as variables in case the defaults are wrong
  121. ;;; on your machine \(and for efficiency).
  122.  
  123. (defvar shadow-system-name (system-name)
  124.   "The complete hostname of this machine.")
  125.  
  126. (defvar shadow-homedir nil
  127.   "Your home directory on this machine.")
  128.  
  129. ;;;
  130. ;;; Internal variables whose values are stored in the info and todo files:
  131. ;;;
  132.  
  133. (defvar shadow-clusters nil
  134.   "List of host clusters \(see shadow-define-cluster).")
  135.  
  136. (defvar shadow-literal-groups nil
  137.   "List of files that are shared between hosts.
  138. This list contains shadow structures with literal filenames, created by
  139. shadow-define-group.")
  140.  
  141. (defvar shadow-regexp-groups nil
  142.   "List of file types that are shared between hosts.
  143. This list contains shadow structures with regexps matching filenames, 
  144. created by shadow-define-regexp-group.")
  145.  
  146. ;;;
  147. ;;; Other internal variables:
  148. ;;;
  149.  
  150. (defvar shadow-files-to-copy nil)    ; List of files that need to
  151.                     ; be copied to remote hosts.
  152.  
  153. (defvar shadow-hashtable nil)        ; for speed
  154.  
  155. (defvar shadow-info-buffer nil)        ; buf visiting shadow-info-file
  156. (defvar shadow-todo-buffer nil)        ; buf visiting shadow-todo-file
  157.  
  158. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  159. ;;; Syntactic sugar; General list and string manipulation
  160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  161.  
  162. (defmacro shadow-when (condition &rest body)
  163.   ;; From cl.el
  164.   "(shadow-when CONDITION . BODY) => evaluate BODY if CONDITION is true."
  165.   (` (if (not (, condition))  ()  (,@ body))))
  166.   
  167. (defun shadow-union (a b)
  168.   "Add members of list A to list B
  169. if they are not equal to items already in B."
  170.   (if (null a)
  171.       b
  172.     (if (member (car a) b)
  173.     (shadow-union (cdr a) b)
  174.       (shadow-union (cdr a) (cons (car a) b)))))
  175.  
  176. (defun shadow-find (func list)
  177.   "If FUNC applied to some element of LIST is nonnil, 
  178. return the first such element."
  179.   (while (and list (not (funcall func (car list))))
  180.     (setq list (cdr list)))
  181.   (car list))
  182.  
  183. (defun shadow-remove-if (func list)
  184.   "Remove elements satisfying FUNC from LIST.
  185. Nondestructive; actually returns a copy of the list with the elements removed."
  186.   (if list
  187.       (if (funcall func (car list))
  188.       (shadow-remove-if func (cdr list))
  189.     (cons (car list) (shadow-remove-if func (cdr list))))
  190.     nil))
  191.  
  192. (defun shadow-join (strings sep)
  193.   "Concatenate elements of the list of STRINGS with SEP between each."
  194.   (cond ((null strings) "")
  195.     ((null (cdr strings)) (car strings))
  196.     ((concat (car strings) " " (shadow-join (cdr strings) sep)))))
  197.  
  198. (defun shadow-regexp-superquote (string)
  199.   "Like regexp-quote, but includes the ^ and $ 
  200. to make sure regexp matches nothing but STRING."
  201.   (concat "^" (regexp-quote string) "$"))
  202.  
  203. (defun shadow-suffix (prefix string)
  204.   "If PREFIX begins STR